import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.List;

import static java.lang.Thread.sleep;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/9/4 14:14
 * 校验
 */
public class Main02 {

    public static void main(String[] args) throws InterruptedException {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(chromeOptions);
        // 打开百度首页
        webDriver.get("https://www.baidu.com");
        // 输入框输入 软件测试
        WebElement element = webDriver.findElement(By.cssSelector(".s_ipt"));
        element.sendKeys("软件测试");
        // 找到百度一下按钮并点击
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        // 校验
//        List<WebElement> elements = webDriver.findElements(By.cssSelector("a em"));
//        for (int i = 0; i < elements.size(); i++) {
////            System.out.println(elements.get(i).getText());
//        }
        // 清空内容, 搜索 小黄 然后点击百度一下
        webDriver.findElement(By.cssSelector("#kw")).clear();
        sleep(3000);
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("小黄");
        webDriver.findElement(By.cssSelector("#su")).click();
    }
}
